#!/usr/bin/env python
# -*- coding: utf-8 -*-
import abc
from app.utils.XDB2Utils import XDB2Utils


class AbstractStateJob(object):
    __metaclass__ = abc.ABCMeta

    config = None

    ok = None
    conn = None

    unit_code = None

    def __init__(self, p_config=None, p_unit_code: str = None):
        self.config = p_config
        self.unit_code = p_unit_code
        self.ok, self.conn = XDB2Utils.db_connect(p_user=self.config.DB_USER,
                                                  p_host=self.config.DB_HOST,
                                                  p_port=self.config.DB_PORT,
                                                  p_passwd=self.config.DB_PASSWORD,
                                                  p_db_name=self.config.DB_INSTANCE_NAME)

        print('is DB2 connected in AbstractStateJob-->>{}\n'.format(self.ok))

    @abc.abstractmethod
    def execute(self):
        print('AbstractStateJob.execute close the db connection')

        XDB2Utils.db_close(p_conn=self.conn)
        pass
